<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <!-- <script src="ajax.js" type="text/javascript" charset="utf-8"></script> -->
  <!-- <script src="../cookie/cookie.js" type="text/javascript" charset="utf-8"></script> -->
  <title>Document</title>
  <link rel="stylesheet" href="./login.css">
</head>

<body>
  <div class="loginContainer">
    <h1>登录</h1>
    <form  action="./checkUser.php" onsubmit="return false" method="post">姓名：
      <input class="inputStyle1 inputStyle username" type="text" name="username" />
      <span class="exchange">用户名不正确</span>
      <br />密码：
      <input class="inputStyle pwd" type="password" name="pwd" /><br />
      记住我 <input type="checkbox" class="remeber" />
      <input class="loginStyle" type="submit" value="登录" />
    </form>
  </div>
</body>
<script>
  let loginStyle = document.querySelector(".loginStyle");
  let user = document.querySelector(".username");
  let pwdele = document.querySelector(".pwd");

  loginStyle.onclick = function () {
    let username = user.value;
    let pwd = pwdele.value;
    
    let xhr = new XMLHttpRequest();
    xhr.open("post","/login/submit");
    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    
    // xhr.onreadystatechange = function(){
      xhr.onload = function(){
        let res = JSON.parse(xhr.responseText);
        console.log(res);
        if(res.status==1){
          window.location.href = "addnew.html"
        }else{
          console.log(0);
        }
      }
      let str=`username=${username}&pwd=${pwd}`
      xhr.send(str);
  // }
}



</script>

</html>